51C - Three Base Stations - CodeForces Solution


binary search greedy *1800

Please click on ads to support us..

C++ Code:

//" إنّ إله السّماء يعطينا النّجاح، ونحن عبيده نقوم ونبني" (سفر نحميا 20:2)
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
#define el "\n"
#define _3en_7oras_ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void do_it()
{


    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    double s = 0,e = 1e9,mid,ret;
    vector<double> ans;
    while(e-s>1e-7)
    {
        mid = (s+e)/2;
        double last = a[0] + mid ;
        int cnt = 1;
        vector<double> temp;
        temp.push_back(last);
        for(int i = 1;i<n;i++)
        {
            if(abs(a[i]-last)-1e-7>mid)
            {
                last = a[i] + mid;
                temp.push_back(last);
                cnt++;
            }
        }
        if(cnt<=3)
        {
            ret = mid ;
            e = mid - 1e-8;
            ans = temp;;

        }
        else s = mid + 1e-8;

    }
    while(ans.size()<3)
        ans.push_back(1);
    cout<<fixed<<setprecision(6)<<ret<<el;
    for(auto j:ans)
        cout<<j<<" ";


}

int main()
{

    _3en_7oras_
    int T = 1;
  //  cin >> T;
    for (int i = 1; i <= T; i++)
        do_it();


    return 0;
}

 	 	  	 	  		 		 						 		  	 	


Comments

Submit
0 Comments
More Questions

45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders